home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Diamond Collection
/
The Diamond Collection (Software Vault)(Digital Impact).ISO
/
cdr13
/
aurora2c.zip
/
CALCPAD.AML
< prev
next >
Wrap
Text File
|
1995-04-07
|
8KB
|
289 lines
/* ------------------------------------------------------------------ */
/* Macro: CALCPAD.AML */
/* Written by: nuText Systems */
/* */
/* Description: This macro displays a simple calculator pad with */
/* basic arithmetic operations, a memory, and four */
/* display lines. Floating point numbers are not */
/* supported. The number on the bottommost display */
/* line can be entered into the text of the current */
/* edit window. */
/* */
/* Usage: Select this macro from the 'Sample Utility Macros' */
/* menu or from the macro picklist <shift f12>. Numbers */
/* and operations can be entered by using the keyboard */
/* or the mouse. */
/* */
/* If you use this macro regularly, it may be */
/* convenient to assign it to a key. For example: */
/* */
/* object edit */
/* . */
/* . */
/* key <alt k> */
/* runmacro getbootpath + "MACRO\\CALCPAD.X" */
/* end */
/* */
/* ------------------------------------------------------------------ */
include bootpath "define.aml"
// define the colors to use
define
set calc_display_color color darkgray on green
set calc_display_curr_color color black on green
set calc_button_color color black on green
set calc_client_color color black on gray
set calc_border_color color white on gray
set calc_control_color color yellow
end
// display lines
var line1
var line2
var line3
var line4
// display operators
var op0
var op1
var op2
var op3
var op4
// numeric base
radix = 10
// clear the calculator display
function cleardisp
line1 = ''
line2 = ''
line3 = ''
line4 = 0
op0 = ' '
op1 = ' '
op2 = ' '
op3 = ' '
op4 = ' '
end
// scroll the display upwards
function scrollup
op0 = op1
line1 = line2
op1 = op2
line2 = line3
op2 = op3
line3 = line4
op3 = op4
line4 = 0
op4 = ' '
end
// perform the operation currently on the display
function result
value = case op3
when '+' line3 + line4
when '-' line3 - line4
when '*' line3 * line4
when '/' line3 / line4
when 'm' line3 mod line4
when '%' (line3 * line4) / 100
end
scrollup
line4 = value
end
// create the calculator window
createwindow
setwinobj
setframe ">b"
setcolor border_color calc_border_color
setcolor text_color calc_client_color
setcolor control_color calc_control_color
settitle "Calculator"
setwinctrl '≡'
sizewindow 36 5 72 20 "ad"
setborder "1i"
setshadow 2 1
// define strings to display in the keypad
keystr = " C % mod / CE 7 8 9 * MR 4 5 6 - MS 1 2 3 + M+ 0 +/- = "
x = 0
y = 0
// draw the keypad
gotoxy 3 7
while y < 5 do
while x < 5 do
writestr keystr [y * 25 + (x * 5) + 1 : 5] calc_button_color
writestr " "
x = x + 1
end
x = 0
y = y + 1
if y < 5 then
writeline
writeline
gotoxy 3
end
end
y = 0
// clear the display
cleardisp
// do for each keypress or buttonclick
loop
// draw the calculator display
gotoxy 3 2
writestr op0 + (pad (thousands line1) 32 'r') calc_display_color
gotoxy 3 3
writestr op1 + (pad (thousands line2) 32 'r') calc_display_color
gotoxy 3 4
writestr op2 + (pad (thousands line3) 32 'r') calc_display_color
gotoxy 3 5
writestr (if? op3 == '=' ' ' op3) + (pad (thousands line4) 32 'r')
calc_display_curr_color
// display the window and get the next key
keycode = getkey
chr = locase (char (keycode & 0ffh))
case keycode
// exit the calculator
when <esc>
break
// mouse click
when <button>
// left mouse button only
if button? 1 then
case getregion
// client area
// translate mouse click to keypress
when 1
buttonline = case virtorow
when 7 "cb%m/"
when 9 "e789*"
when 11 "r456-"
when 13 "s123+"
when 15 "z0ti="
end
column = virtocol
buttonchar = buttonline [
if column >= 3 and column <= 7 then 1
elseif column >= 10 and column <= 14 then 2
elseif column >= 17 and column <= 21 then 3
elseif column >= 24 and column <= 28 then 4
elseif column >= 31 and column <= 35 then 5
else 6
end
]
// simulate the appropriate keypress
if buttonchar then
queuekey (getkeycode '<'+ buttonchar + '>')
end
// close icon
when 51
break
end
end
// clear the display
when <c>, <del>
cleardisp
// clear the entry line
when <e>
line4 = 0
op4 = ' '
op3 = ' '
// store
when <s>
memory = line4
// recall
when <r>
line4 = memory
// store + memory
when <z>
memory = memory + line4
// change sign
when <i>
line4 = -line4
op4 = ' '
op3 = ' '
// enter into text
when <t>, <ctrl enter>
queue "write" (thousands line4)
break
// backspace
when <b>, <backspace>
line4 = line4 / radix
op4 = ' '
op3 = ' '
// enter numeric characters
when <0>, <1>, <2>, <3>, <4>, <5>, <6>, <7>, <8>, <9>
if chr < radix then
if op3 == '=' then
scrollup
end
positive = line4 >= 0
oldline = line4
line4 = line4 * radix + chr
// test for overflow
if positive <> (line4 > 0) then
line4 = oldline
end
end
// operators
when <+>, <->, <*>, </>, <%>, <m>
if op3 <> ' ' and op3 <> '=' then
op4 = '='
result
end
op4 = chr
scrollup
// do the current operation
when <=>, <enter>
if op3 <> ' ' then
if op3 == '=' then
op4 = op2
scrollup
line4 = line2
end
op4 = '='
result
end
// unrecognized key
otherwise
beep 200 70
end
end
// destroy the calculator window
destroywindow